<?
global $db;
$e = inc_incfile("wiki/global.php",$params);
$link = $e["link"];
skin_param("title","Revision History");

if ($_POST["latest"]) {
	_wiki_latest($link,$_POST["latest"]);
	}

$r = $db->query("select wiki.*, users.title as users_title from wiki ".
	" left join users on users.id = wiki.users_id ".
	" where ".
	" link = ".$db->sqlstring($link).
	" order by datetimeon desc ".
	"");
	
echo "<form method='post'>";
echo "<table>";
echo "<tr><th>latest<th>datetimeon<th>edited by<th>changes";
$pid = 0;
$type = $e["type"];
foreach ($r as $e) {
	if (in_array($type,array("page","code"))) {
		if ($pid) echo "<td><a href=\"diff.php?link=$link&oldid={$e["id"]}&newid=$pid\">diff</a>";
		}
	if (!$e["users_title"]) $e["users_title"] = "Anonymous";
	echo "<tr>";
	echo "<td><input type='radio' name='latest' value='{$e["id"]}'".($e["latest"]?" checked":"").">";
	echo "<td>{$e["datetimeon"]}";
	echo "<td>".htmlentities($e["users_title"]);
	echo "<td>".htmlentities($e["changes"]);
	echo "<td><a href=\"view.php?link=$link&id={$e["id"]}\">view</a>";
	echo "<td><a href=\"source.php?link=$link&id={$e["id"]}\">source</a>";
	$pid=$e["id"];
	}
echo "</table>";
echo "<input type='submit' value='Continue'></form>";
?>